package com.cotton.page.feature.orm.dialect;

/**
 * 版权：
 * 功能：Oracle
 * 作者：朱伟峰
 * 邮箱：zhuweifeng24@gmail.com
 * 日期：2015年12月2日
 */
public class OracleDialect extends Dialect
{

	@Override
	public String getLimitString(String sql, int offset, int limit)
	{

		sql = sql.trim();
		boolean isForUpdate = false;
		if (sql.toLowerCase().endsWith(" for update"))
		{
			sql = sql.substring(0, sql.length() - 11);
			isForUpdate = true;
		}

		StringBuffer pagingSelect = new StringBuffer(sql.length() + 100);

		pagingSelect
				.append("select * from ( select row_.*, rownum rownum_ from ( ");

		pagingSelect.append(sql);

		pagingSelect.append(" ) row_ ) where rownum_ > " + offset
				+ " and rownum_ <= " + (offset + limit));

		if (isForUpdate)
		{
			pagingSelect.append(" for update");
		}

		return pagingSelect.toString();
	}

	@Override
	public String getCountString(String sql)
	{
		// TODO Oracle分页查询
		return null;
	}
}
